<script>
    
      function ajax (url,type){
        var xhr=new XMLHttpRequest();  
       
        if(type=="get"&&data!==undefined){

          
          url+="?"+data;

        }
        xhr.open(tyep,url,true);
        xhr.onreadystatechange=fucntion(){
          if(xhr.readyState==4){
            var  result=JSON.parse(xhr.responseText);
          }
        }

        if(type="post"){ 
          xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        }

        if(type=="post"){ 
          xhr.send(data);
        }else { 
          xhr.send();
        }
      }
    </script>